﻿using Microsoft.AspNetCore.Mvc;
using MyECommerceProject.Interfaces;
using MyECommerceProject.Models;

namespace MyECommerceProject.Controllers
{
    [ApiController]
    [Route("api/[controller]")]
    public class InventoryController : ControllerBase
    {
        private readonly IInventoryService _inventoryService;

        public InventoryController(IInventoryService inventoryService)
        {
            _inventoryService = inventoryService;
        }

        [HttpPost]
        public async Task<IActionResult> AddInventoryRecord([FromBody] Inventory inventory)
        {
            await _inventoryService.AddInventoryRecordAsync(inventory.ProductId, inventory.Sell, inventory.Count);
            return Ok();
        }

        [HttpGet]
        public async Task<IActionResult> GetInventoryRecords([FromQuery] int productId, [FromQuery] DateOnly startDate, [FromQuery] DateOnly endDate)
        {
            var records = await _inventoryService.GetInventoryRecordsAsync(productId, startDate, endDate);
            return Ok(records);
        }
    }
}
